package com.spark.lola.logistics.entity;

import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.spark.lola.logistics.constant.LogisticsConstant;
import com.spark.lola.logistics.vo.DriverVo;
import com.spark.lola.support.mybatis.entity.BaseModel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author: Zhi-peng wang
 * @date: 2020/05/06 10:18
 * 货运支出单信息
 **/
@Getter
@Setter
@AllArgsConstructor
@ApiModel(value = "ExpensesInfo", description = "货运支出单信息")
@TableName("logistics_expenses_info")
public class ExpensesInfo extends BaseModel {

    @ApiModelProperty(name = "no", value = "流水号")
    private String no;

    @ApiModelProperty(name = "empId", value = "申请人id")
    private Long empId;

    @ApiModelProperty(name = "toOrderId", value = "直达车运输单id")
    private Long toOrderId;

    @ApiModelProperty(name = "toOrderNo", value = "直达车运输单号")
    private String toOrderNo;

    @ApiModelProperty(name = "returnOrderId", value = "回头车运输单id")
    private Long returnOrderId;

    @ApiModelProperty(name = "returnOrderNo", value = "回头车运输单号")
    private String returnOrderNo;

    @ApiModelProperty(name = "preMileage", value = "上次里程数（km）")
    private Integer preMileage;

    @ApiModelProperty(name = "nowMileage", value = "本次里程数（km）")
    private Integer nowMileage;

    @ApiModelProperty(name = "fuelConsumption", value = "加油量（L）油耗（L）")
    private BigDecimal fuelConsumption;

    @ApiModelProperty(name = "fuelPrice", value = "燃油单价")
    private BigDecimal fuelPrice;

    @ApiModelProperty(name = "aveConsumption", value = "油耗（L）")
    private BigDecimal aveConsumption;

    @ApiModelProperty(name = "totalFuel", value = "总油费")
    private BigDecimal totalFuel;

    @ApiModelProperty(name = "borrowingAmount", value = "借款金额")
    @TableField(exist = false)
    private BigDecimal borrowingAmount;

    @ApiModelProperty(name = "borrowingTime", value = "借款时间")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat("yyyy-MM-dd")
    @TableField(exist = false)
    private Date borrowingTime;

    @ApiModelProperty(name = "totalCost", value = "费用总额")
    private BigDecimal totalCost;

    @ApiModelProperty(name = "refundableFee", value = "应退费用")
    private BigDecimal refundableFee;

    @ApiModelProperty(name = "isRejected", value = "驳回标志", notes = "0-正常，1-驳回")
    private Integer isRejected;

    @ApiModelProperty(name = "status", value = "状态", notes = "0-待审核，1-财务审核，2-待退款，3-已完成，-1-已取消")
    private Integer status;

    @ApiModelProperty(name = "remark", value = "备注")
    private String remark;

    @ApiModelProperty(name = "creator", value = "创建人")
    @TableField(fill = FieldFill.INSERT)
    private String creator;

    @ApiModelProperty(name = "updator", value = "修改人")
    @TableField(fill = FieldFill.UPDATE)
    private String updator;

    @ApiModelProperty(name = "createTime", value = "创建时间")
    @TableField(fill = FieldFill.INSERT)
    private Date createTime;

    @ApiModelProperty(name = "updateTime", value = "修改时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;

    @ApiModelProperty(name = "expensesDetailList", value = "支出单详情集合")
    @TableField(exist = false)
    private List<ExpensesDetail> expensesDetailList = new ArrayList<>();

    @ApiModelProperty(name = "driverVo", value = "驾驶员信息")
    @TableField(exist = false)
    private DriverVo driverVo;

    @ApiModelProperty(name = "expensesProcessList", value = "支出单流程集合")
    @TableField(exist = false)
    private List<ExpensesProcess> expensesProcessList = new ArrayList<>();

    @ApiModelProperty(name = "semitrailerNo", value = "挂车车牌")
    @TableField(exist = false)
    private String semitrailerNo;

    @ApiModelProperty(name = "toOrderInfo", value = "直达车信息")
    @TableField(exist = false)
    private OrderInfo toOrderInfo;

    @ApiModelProperty(name = "returnOrderInfo", value = "回头车信息")
    @TableField(exist = false)
    private OrderInfo returnOrderInfo;

    public ExpensesInfo() {
        // 数值初始化
        this.preMileage = 0;
        this.nowMileage = 0;
        this.fuelConsumption = BigDecimal.ZERO;
        this.fuelPrice = BigDecimal.ZERO;
        this.borrowingAmount = BigDecimal.ZERO;
        this.totalCost = BigDecimal.ZERO;
        this.refundableFee = BigDecimal.ZERO;
        // 状态初始化赋值
        this.isRejected = LogisticsConstant.IsRejected.NO;
        this.status = LogisticsConstant.ExpensesStatus.WAIT_AUDIT;
    }

    public ExpensesInfo(Long id, Integer status) {
        this.id = id;
        this.status = status;
    }

}
